{% extends "admin/base.html" %}
{% block title %}-添加用户{% endblock %}
{% block user %}current-item{% endblock %}
{% block mainbody %}
    <div class="main">
        <center>
            <h1>添加用户</h1>
            <span id="error" class="error">{{ error }}</span>
            <form id="user-form" method="post" action="/admin/user_add">
                <table class="table-adduser">
                    <tr>
                        <th>
                            <span>用户名:</span>
                        </th>
                        <td>
                            <input type="text" class="user_name" name="user_name" maxlength="20" placeholder="max 20">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span>性别:</span>
                        </th>
                        <td>
                            <input type="radio" class="user_sex" name="user_sex" value="男" /><span>男</span>
                            <input type="radio" class="user_sex" name="user_sex" value="女" /><span>女</span>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span>出生日期:</span>
                        </th>
                        <td>
                            <input type="date" class="user_birth" name="user_birth" value=""/>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span>手机号:</span>
                        </th>
                        <td>
                            <input type="text" class="user_phone" name="user_phone" maxlength="11" placeholder="max 11">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span>用户名:</span>
                        </th>
                        <td>
                            <input type="text" class="user_nick" name="user_nick" maxlength="20" placeholder="max 20">
                            <span class="error">*</span>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span>密码:</span>
                        </th>
                        <td>
                            <input type="password" class="user_pwd" name="user_pwd" maxlength="16" placeholder="max 16">
                            <span class="error">*</span>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span>管理员:</span>
                        </th>
                        <td>
                            <input type="radio" class="is_admin" name="is_admin" value="1" /><span>是</span>
                            <input type="radio" class="is_admin" name="is_admin" value="0" checked="checked" /><span>否</span>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <span>职位:</span>
                        </th>
                        <td>
                            <input type="radio" class="position" name="position" value="1" /><span>领导</span>
                            <input type="radio" class="position" name="position" value="0" checked="checked" /><span>员工</span>
                        </td>
                    </tr>
                </table>
                <input type="button" id="submit_btn" value="提交">
            </form>

        </center>
    </div>

    <script src="/public/js/common/jquery-1.12.4.min.js"></script>
    <script>
        $(document).keydown(function(event) {
            if(event.keyCode == 13) {
                submitForm()
            }
        });

        $("#submit_btn").click(function() {
            submitForm()
        })

        function  submitForm() {
            if (checkForm()) {
                $("#error").html("正在提交...");
                $("#user-form").submit();
            }
        }

        function checkForm() {
            console.log($("#user_phone").val())
            $("#error").html("");
            if($(".user_nick").val().trim() == '') {
                $("#error").html("请输入nick");
                return false;
            }
            if($(".user_pwd").val().trim() == '') {
                $("#error").html("请输入pwd");
                return false;
            }
            return true;
        }

        $(".user_nick").blur(function() {
            checkForm()
        })

        $(".user_pwd").blur(function() {
            checkForm()
        })

    </script>
{% endblock %}

